﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AMatysiak.Controls
{
    public class DataGridViewCalendarColumn : DataGridViewColumn
    {
        public DataGridViewCalendarColumn() : base(new DataGridViewCalendarCell()) { }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                if (isNotDataGridViewCalendarCalendarCell(value))
                    throw new InvalidCastException("Must be a DataGridViewCalendarCell");

                base.CellTemplate = value;
            }
        }

        private static bool isNotDataGridViewCalendarCalendarCell(DataGridViewCell value)
        {
            return value != null && !value.GetType().IsAssignableFrom(typeof(DataGridViewCalendarCell));
        }
    }    
}
